package com.maket.jbxx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.maket.jbxx.domain.CpAndSx;
import com.maket.jbxx.service.ICpAndSxService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 产品与属性Controller
 * 
 * @author ruoyi
 * @date 2024-07-11
 */
@RestController
@RequestMapping("/sx")
public class CpAndSxController extends BaseController
{
    @Autowired
    private ICpAndSxService cpAndSxService;

    /**
     * 查询产品与属性列表
     */
    @RequiresPermissions("jbxx:sx:list")
    @GetMapping("/list")
    public TableDataInfo list(CpAndSx cpAndSx)
    {
        startPage();
        List<CpAndSx> list = cpAndSxService.selectCpAndSxList(cpAndSx);
        return getDataTable(list);
    }

    /**
     * 导出产品与属性列表
     */
    @RequiresPermissions("jbxx:sx:export")
    @Log(title = "产品与属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CpAndSx cpAndSx)
    {
        List<CpAndSx> list = cpAndSxService.selectCpAndSxList(cpAndSx);
        ExcelUtil<CpAndSx> util = new ExcelUtil<CpAndSx>(CpAndSx.class);
        util.exportExcel(response, list, "产品与属性数据");
    }

    /**
     * 获取产品与属性详细信息
     */
    @RequiresPermissions("jbxx:sx:query")
    @GetMapping(value = "/{cpSxId}")
    public AjaxResult getInfo(@PathVariable("cpSxId") Long cpSxId)
    {
        return success(cpAndSxService.selectCpAndSxByCpSxId(cpSxId));
    }

    /**
     * 新增产品与属性
     */
    @RequiresPermissions("jbxx:sx:add")
    @Log(title = "产品与属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CpAndSx cpAndSx)
    {
        return toAjax(cpAndSxService.insertCpAndSx(cpAndSx));
    }

    /**
     * 修改产品与属性
     */
    @RequiresPermissions("jbxx:sx:edit")
    @Log(title = "产品与属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CpAndSx cpAndSx)
    {
        return toAjax(cpAndSxService.updateCpAndSx(cpAndSx));
    }

    /**
     * 删除产品与属性
     */
    @RequiresPermissions("jbxx:sx:remove")
    @Log(title = "产品与属性", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cpSxIds}")
    public AjaxResult remove(@PathVariable Long[] cpSxIds)
    {
        return toAjax(cpAndSxService.deleteCpAndSxByCpSxIds(cpSxIds));
    }
}
